package com.tanggh.test;

import java.sql.Timestamp;
import java.util.Date;
import java.util.List;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import com.tanggh.dao.UserDao;
import com.tanggh.entity.PersonalCer;
import com.tanggh.entity.User;
import com.tanggh.service.PersonalCerService;
import com.tanggh.service.UserService;

public class MainClass {
	
	private BeanFactory beanFactory = null;
	
	public static void main(String[] args) {
		
		BeanFactory beanFactory = new ClassPathXmlApplicationContext("applicationContext-*.xml");
		
		/*Person person = new Person();
		person.setName("王大大");
		person.setSex("男");
		
		PersonAction action = (PersonAction) beanFactory.getBean("personAction");
		action.setPerson(person);
		
		action.execute();
		System.out.println("ok");*/
		PersonalCer p = new PersonalCer();
		p.setCityCode("01000");
		p.setJobCategoryCode("02555");
		p.setContact("tanggaohong");
		p.setCreateDate(new Timestamp(new Date().getTime()));
		p.setDescription("description");
		p.setQq("63495645");
		p.setMobileNumber("15988889999");
		p.setFromUrl("http://www.baidu.com");
		p.setIp("192.168.168.0");
		p.setSalaryId(1);
		
		PersonalCerService personalCerService = (PersonalCerService)beanFactory.getBean("personalCerServiceImpl");
		personalCerService.save(p);
		System.out.println("ok");
		
	}
	@Before
	public void testBefore() {
		beanFactory = new ClassPathXmlApplicationContext("applicationContext-*.xml");
	}
	
	@Test
	public void testDao() {
		UserDao userDao = (UserDao)beanFactory.getBean("userDaoImpl");
		System.out.println("ok");
	}
	
	@Test
	public void testService() {
		UserService userService = (UserService)beanFactory.getBean("userServiceImpl");
		User user = new User();
		user.setEmail("陆吉平");
		user.setPassword("aaaaaa");
		user.setCompanyName("地产公司");
		user.setMobilePhone("15966669999");
		user.setQq("63419666");
		user.setUserType(1);
		user.setRegisterDate(new Timestamp(new Date().getTime()));
		user.setLatestLoginDate(new Timestamp(new Date().getTime()));
		user.setLatestLoginIp("192.168.1.1");
		
		userService.save(user);
		System.out.println(user.getId());
		System.out.println("ok");
	}
	
	@Test
	public void testListAll() {
		UserService userService = (UserService)beanFactory.getBean("userServiceImpl");
		List<User> list = userService.listAll();
		for(User u: list ) {
			System.out.println( u.getEmail());
		}
	}
	
	@Test
	public void testProvinceDao() {
	}
	
	@Test
	public void testPersonalCer() {
		PersonalCer p = new PersonalCer();
		p.setCityCode("01000");
		p.setJobCategoryCode("02555");
		p.setContact("tanggaohong");
		p.setCreateDate(new Timestamp(new Date().getTime()));
		p.setDescription("description");
		p.setQq("63495645");
		p.setMobileNumber("15988889999");
		p.setFromUrl("http://www.baidu.com");
		p.setIp("192.168.168.0");
		p.setSalaryId(1);
		
		PersonalCerService personalCerService = (PersonalCerService)beanFactory.getBean("personalCerServiceImpl");
		personalCerService.save(p);
		System.out.println("ok");
	}
}
